package io.github.junxworks.qt.modules.tushare.mapper;

import java.util.List;

import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import io.github.junxworks.ep.core.orm.BaseMapper;
import io.github.junxworks.qt.modules.data.vo.DStockProfileVo;
import io.github.junxworks.qt.modules.tushare.entity.DStockConceptUseful;
import io.github.junxworks.qt.modules.tushare.entity.DStockProfile;

/**
 * @program :springbootdev
 * @description:
 * @author:Junxworks
 * @create:2019-08-16 19:49
 */
@Mapper
public interface BaseInfoMapper extends BaseMapper {
	int saveStockProfiles(List<DStockProfile> datas);

	void clearStockProfiles(String listStatus);

	@Delete("delete from d_stock_company where exchange=#{exchange}")
	int clearStockCompanyInfo(String exchange);

	@Delete("delete from d_stock_stk_rewards where end_date=#{endDate}")
	int clearStkRewardsByEndDate(String endDate);
	
	List<String> loadAllStockCodesForSina();

	List<String> loadAllStockCodesForTushare();

	@Select("select * from d_stock_profile")
	List<DStockProfileVo> queryAllStockProfiles();

	@Select("select * from d_stock_profile where list_status!='D'")
	List<DStockProfileVo> queryAllAvailableStockProfiles();

	@Select("select * from d_stock_profile where ts_code=#{stockCode}")
	DStockProfileVo queryStockProfileByCode(String stockCode);

	@Select("select * from d_stock_profile where symbol=#{symbol}")
	DStockProfileVo queryStockProfileBySymbol(String symbol);

	@Delete("delete from d_stock_concept")
	int deleteStockConcept();

	@Delete("delete from d_stock_index_classify")
	int deleteStockIndexClassify();

	@Select("select index_code from d_stock_index_classify")
	List<String> queryAllStockIndexClassifyCode();
	
	@Delete("delete from d_stock_index_member where index_code=#{index}")
	int deleteStockIndexMember(@Param("index") String index);

	
	@Select("select code from d_stock_concept")
	List<String> queryAllStockConcept();

	@Delete("delete from d_stock_concept_detail where id=#{id}")
	int deleteStockConceptDetailByConceptId(String id);

	@Delete("delete from d_stock_concept_useful")
	int clearConceptUseful();

	List<DStockConceptUseful> selectConceptUsefulData();
	
	@Select("select * from d_stock_profile where list_date <= #{endDate}")
	List<DStockProfileVo> selectStockProfileBefore(String endDate);
	
	@Select("select period from d_stock_finance_period order by period desc")
	List<Integer> queryFinancePeriods();
}
